<?php

class Admin_Model_Forum extends Zend_Db_Table_Abstract
{
    
    protected $_name = 'forum_forums';

    /**
     * 创建版块
     *
     * @param int $cat_id
     * @param string $name
     * @param string $description
     */
    public function createForum($cat_id,$name,$description){
    
        $row = $this->createRow();
        
        if($row){
            $row->cat_id = $cat_id;
            $row->name = $name;
            $row->description = $description;
            $row->save();
            return $row->id;
        } else {
            return null;
        }
        
    }
    
    /**
     * 更新版块
     *
     * @param int $id
     * @param int $cat_id
     * @param string $name
     * @param string $description
     */
    public function updateForum($id, $cat_id, $name, $description){
        $row = $this->find($id)->current();
        if ($row) {
            $row->cat_id = $cat_id;
            $row->name = $name;
            $row->description = $description;
            $row->save();
            return true;
        }
        else{
            return false;
        }
    }
    
    /**
     * 删除版块
     *
     * @param int $id
     * @throws Zend_Exception
     */
    public function deleteForum($id){
        
        $row = $this->find($id)->current();
        if($row){
            $row->delete();
            return true;
        } else {
            throw new Zend_Exception('删除版块失败');
        }
    }
}